<template>
	<view class="register-container">
		<view class="logo">
			<image class="logo-img" src="/static/login.png" mode="aspectFit"></image>
			<text class="title">智能直播课堂</text>
		</view>

		<view class="form">
			<view class="input-group">
				<uni-icons type="person" size="20" color="#999" />
				<input type="text" v-model="formData.username" placeholder="请输入用户名" />
			</view>

			<view class="input-group">
				<uni-icons type="locked" size="20" color="#999" />
				<input type="password" v-model="formData.password" placeholder="请输入密码" />
			</view>

			<view class="input-group">
				<uni-icons type="locked" size="20" color="#999" />
				<input type="password" v-model="formData.confirmPassword" placeholder="请确认密码" />
			</view>

			<view class="input-group">
				<uni-icons type="phone" size="20" color="#999" />
				<input type="number" v-model="formData.phone" maxlength="11" placeholder="请输入手机号" />
			</view>

			<view class="verify-group">
				<view class="input-group verify">
					<uni-icons type="email" size="20" color="#999" />
					<input type="number" v-model="formData.code" maxlength="6" placeholder="请输入验证码" />
				</view>
				<button class="verify-btn" :disabled="counting"
					@click="getVerifyCode">{{ counting ? `${count}s后重新获取` : '获取验证码' }}</button>
			</view>

			<button class="register-btn" @click="handleRegister">注册</button>

			<view class="login-link">
				已有账号？<text class="link" @click="goToLogin">立即登录</text>
			</view>
		</view>

		<view class="footer">
			<view class="copyright">© 2024 智能直播课堂 版权所有</view>
			<view class="policy">
				<text class="link">隐私政策</text>
				<text class="separator">|</text>
				<text class="link">用户协议</text>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref, reactive } from 'vue';

	const formData = reactive({
		username: '',
		password: '',
		confirmPassword: '',
		phone: '',
		code: ''
	});

	const count = ref(60);
	const counting = ref(false);

	const getVerifyCode = () => {
		if (counting.value) return;
		counting.value = true;
		const timer = setInterval(() => {
			count.value--;
			if (count.value <= 0) {
				clearInterval(timer);
				counting.value = false;
				count.value = 60;
			}
		}, 1000);
	};

	const handleRegister = () => {
		// 处理注册逻辑
		console.log('注册信息：', formData);
	};

	const goToLogin = () => {
		uni.navigateBack();
	};
</script>

<style>
	page {
		height: 100%;
	}

	.register-container {
		min-height: 100%;
		padding: 0 40rpx;
		background: linear-gradient(135deg, #1976D2 0%, #64B5F6 50%, #E3F2FD 100%);
		display: flex;
		flex-direction: column;
		position: relative;
	}

	.logo {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 120rpx;
		margin-bottom: 80rpx;
		z-index: 10;
		position: relative;
	}

	.logo-img {
		width: 120rpx;
		height: 120rpx;
		margin-bottom: 20rpx;
		display: block;
	}

	.title {
		margin-top: 20rpx;
		font-size: 32px;
		color: #FFFFFF;
		font-weight: 500;
	}

	.form {
		flex: 1;
		background: rgba(255, 255, 255, 0.95);
		border-radius: 20rpx;
		padding: 40rpx;
		margin: 0 20rpx;
		margin-top: 20rpx;
		backdrop-filter: blur(10px);
		box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
		position: relative;
		z-index: 1;
	}

	.input-group {
		display: flex;
		align-items: center;
		height: 88rpx;
		padding: 0 20rpx;
		margin-bottom: 32rpx;
		border: 1px solid #e5e5e5;
		border-radius: 8px;
		background-color: #fff;
	}

	.input-group input {
		flex: 1;
		margin-left: 20rpx;
		font-size: 14px;
	}

	.verify-group {
		display: flex;
		gap: 20rpx;
	}

	.verify {
		flex: 1;
		margin-bottom: 0;
	}

	.verify-btn {
		width: 200rpx;
		height: 88rpx;
		line-height: 88rpx;
		font-size: 14px;
		color: #1976D2;
		background-color: #fff;
		border: 1px solid #1976D2;
		border-radius: 8px;
		padding: 0;
	}

	.verify-btn[disabled] {
		color: #999;
		border-color: #e5e5e5;
		background-color: #f5f5f5;
	}

	.register-btn {
		width: 100%;
		height: 88rpx;
		line-height: 88rpx;
		margin-top: 60rpx;
		color: #fff;
		font-size: 16px;
		background: linear-gradient(135deg, #1976D2 0%, #64B5F6 100%);
		border-radius: 8px;
		transition: all 0.3s;
		border: none;
	}

	.register-btn:active {
		transform: scale(0.98);
		background: linear-gradient(135deg, #1565C0 0%, #42A5F5 100%);
	}

	.login-link {
		margin-top: 32rpx;
		text-align: center;
		font-size: 14px;
		color: #666;
	}

	.link {
		color: #1976D2;
		text-decoration: none;
	}

	.footer {
		padding: 40rpx 0;
		text-align: center;
	}

	.copyright {
		font-size: 12px;
		color: #999;
		margin-bottom: 16rpx;
	}

	.policy {
		font-size: 12px;
	}

	.separator {
		margin: 0 16rpx;
		color: #999;
	}
</style>